Skip to content

Kafka handle position and commit offset on seek operations#3453

Open
ozangunalp wants to merge 4 commits into
smallrye:mainfrom
ozangunalp:kafka_commit_offsets_seek
Open

Kafka handle position and commit offset on seek operations#3453
ozangunalp wants to merge 4 commits into
smallrye:mainfrom
ozangunalp:kafka_commit_offsets_seek

Conversation

@ozangunalp

Copy link
Copy Markdown
Collaborator
  • Latest commit strategy: clear offsets on partition revocation
  • Added clearBuffer to the PausableChannel interface
  • Added onPartitionsSeeked callback to KafkaConsumerRebalanceListener and partitionsSeeked to KafkaCommitHandler interface. On seek operations, the Kafka consumer clears the poller buffer and calls partitionsSeeked on commit handlers.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.76923% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.87%. Comparing base (a96442f) to head (249df9b).
⚠️ Report is 1213 commits behind head on main.

Files with missing lines Patch % Lines
...ve/messaging/kafka/impl/ReactiveKafkaConsumer.java 50.00% 2 Missing and 2 partials ⚠️
...ive/messaging/kafka/impl/OrderedStreamHandler.java 0.00% 2 Missing ⚠️
.../providers/extension/PausableChannelDecorator.java 0.00% 2 Missing ⚠️
...o/smallrye/reactive/messaging/PausableChannel.java 0.00% 1 Missing ⚠️
...essaging/kafka/KafkaConsumerRebalanceListener.java 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #3453      +/-   ##
============================================
+ Coverage     77.47%   77.87%   +0.40%     
- Complexity     3778     5619    +1841     
============================================
  Files           306      486     +180     
  Lines         12673    18774    +6101     
  Branches       1648     2312     +664     
============================================
+ Hits           9818    14620    +4802     
- Misses         2116     3017     +901     
- Partials        739     1137     +398     
Files with missing lines Coverage Δ
...ive/messaging/kafka/commit/KafkaCommitHandler.java 100.00% <100.00%> (ø)
...tive/messaging/kafka/commit/KafkaLatestCommit.java 100.00% <100.00%> (ø)
...ka/commit/KafkaThrottledLatestProcessedCommit.java 91.46% <100.00%> (+0.23%) ⬆️
...ctive/messaging/kafka/impl/RebalanceListeners.java 92.18% <100.00%> (+6.22%) ⬆️
...o/smallrye/reactive/messaging/PausableChannel.java 0.00% <0.00%> (ø)
...essaging/kafka/KafkaConsumerRebalanceListener.java 40.00% <0.00%> (+15.00%) ⬆️
...ive/messaging/kafka/impl/OrderedStreamHandler.java 81.81% <0.00%> (ø)
.../providers/extension/PausableChannelDecorator.java 85.71% <0.00%> (ø)
...ve/messaging/kafka/impl/ReactiveKafkaConsumer.java 80.82% <50.00%> (-1.12%) ⬇️

... and 278 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ozangunalp ozangunalp force-pushed the kafka_commit_offsets_seek branch from 63dfc6b to 249df9b Compare July 7, 2026 14:36
@ozangunalp ozangunalp requested a review from cescoffier July 7, 2026 14:36

@cescoffier cescoffier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should KafkaCheckpointCommit also implement partitionsSeeked?


@Override
public void partitionsSeeked(Collection<TopicPartition> partitions) {
delegate.partitionsSeeked(partitions);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a seek, the ordered groups for the affected partitions are holding a stale state (pending counts, buffered items). This could cause records from the new position to be incorrectly ordered or dropped if the group's pending counter is non-zero.

I think we should consider whether the ordered groups for sought partitions should be canceled and removed, similar to what partitionsRevoked does.

public class KafkaThrottledLatestProcessedCommit extends ContextHolder implements KafkaCommitHandler {

private final Map<TopicPartition, OffsetStore> offsetStores = new HashMap<>();
private final Set<TopicPartition> seekedPartitions = new HashSet<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a copy on write variant - HashSet is not thread-safe.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the offset stores, it is only accessed on the channel context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants